package util.i;

import util.j.TiliListener;
import util.t.tiliList;

import javax.swing.*;
import java.awt.event.ActionEvent;
import java.text.SimpleDateFormat;
import java.util.Calendar;
import java.util.Date;

import static java.lang.System.currentTimeMillis;

public class TiliListenerimpl implements TiliListener {

    tiliList list;
    JTextField text1;
    JTextField text2;
    JTextArea area;
    public void setText1(JTextField text1) {
        this.text1=text1;
    }

    public void setText2(JTextField text2) {
        this.text2=text2;
    }

    public void setText3(JTextArea area) {
        this.area=area;
    }

    public void setlist(tiliList list){
        this.list=list;
    }
    public void actionPerformed(ActionEvent e) {
        try {
            String name = text1.getText();
            Integer num = Integer.parseInt(text2.getText());
            int ti = 160 - num;
            int time = ti * 8;
            Calendar cal = Calendar.getInstance();
            SimpleDateFormat sdf = new SimpleDateFormat("HH:mm");
            SimpleDateFormat sdfbj = new SimpleDateFormat("dd");

            Date date = new Date(currentTimeMillis());
            cal.setTime(date);
            cal.add(Calendar.MINUTE, time);
            Date d2 = cal.getTime();
            list.setList(d2,name);
            text1.setText("");
            text2.setText("");
            String t1 = sdfbj.format(date);
            String t2 = sdfbj.format(d2);
            if (t1.equals(t2)) {
                area.append(name + "  的体力将在  今日  " + sdf.format(d2) + "  集满！\n");
            } else {
                area.append(name + "  的体力将在  明天  " + sdf.format(d2) + "  集满！\n");
            }
        }catch (Exception a){
            a.printStackTrace();
        }

    }
}
